Type.registerNamespace('ModWatch');

ModWatch.ModAlertRadioButton = function(element)
{
    ModWatch.ModAlertRadioButton.initializeBase(this, [element]);

    this._modGroup = '';
    this._notifyModMessage = '';
    this._groupName = null;
    this._isSelected = false;
}

ModWatch.ModAlertRadioButton.prototype = {

	get_modGroup : function()
	{
		return this._modGroup;
	},

	set_modGroup : function(value)
	{
		if (!value || value == null)
			this._modGroup = '';
		else
			this._modGroup = value;
	},

	get_notifyModMessage : function()
	{
		return this._notifyModMessage;
	},

	set_notifyModMessage : function(value)
	{
		if (!value || value == null)
			this._notifyModMessage = '';
		else
			this._notifyModMessage = value;
	},

	get_groupName : function()
	{
		return this._groupName;
	},

	set_groupName : function(value)
	{
		this._groupName = value;
	},

	initialize : function()
	{
        ModWatch.ModAlertRadioButton.callBaseMethod(this, 'initialize');

		this.saveCurrentValue();

		ModWatch.ModAlertRadioButtonTrackerInstance.addRadioButton(this, this.get_groupName());
    },

	dispose : function() {
		ModWatch.ModAlertRadioButtonTrackerInstance.removeRadioButton(this, this.get_groupName());

		ModWatch.ModAlertRadioButton.callBaseMethod(this, 'dispose');
	},

	checkForChange : function()
	{
		var cancelChange = false;

		if (ModWatch.ModManagerInstance &&
			ModWatch.ModManagerInstance.isChangeDetected(this.get_modGroup()))
		{
			if (!confirm(this.get_notifyModMessage()))
				cancelChange = true;
		}

		if (cancelChange)
		{
			// roll back the change
			ModWatch.ModAlertRadioButtonTrackerInstance.revertToSavedValues(this, this.get_groupName());
		}
		else
		{
			// store the new selected index
			ModWatch.ModAlertRadioButtonTrackerInstance.saveCurrentValues(this, this.get_groupName());
		}
		
		return cancelChange;
	},

	revertToSavedValue : function()
	{
		this.get_element().checked = this._isSelected;
	},

	saveCurrentValue : function()
	{
		this._isSelected = this.get_element().checked;
	}

}

ModWatch.ModAlertRadioButton.registerClass('ModWatch.ModAlertRadioButton', Sys.UI.Control);

if (typeof(Sys) !== 'undefined')
	Sys.Application.notifyScriptLoaded();
